package com.ihcil.forecast.demo.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * Create by @baseException on 2022/11/5 8:14
 */

public class Str2Time {
    public static String getImgPath(String Path) {
        String[] split = Path.split("\\\\");
        return "/img/" + split[split.length - 1];
    }

    public static LocalDateTime getPathTime(String str) throws ParseException {
        String[] split = str.split("\\\\");
        String cur_time = split[split.length - 1].split("\\.")[0];

        String format = String.format("%s-%s-%s %s:%s", cur_time.substring(0, 4), cur_time.substring(4, 6), cur_time.substring(6, 8), cur_time.substring(8, 10), cur_time.substring(10, 12));
//        System.out.println(format);
        LocalDateTime time =
                LocalDateTime.parse(format, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
        return time;
    }

    public static LocalDateTime getTime(String cur_time) throws ParseException {
        String format = String.format("%s-%s-%s %s:%s", cur_time.substring(0, 4), cur_time.substring(4, 6), cur_time.substring(6, 8), cur_time.substring(8, 10), cur_time.substring(10, 12));
//        System.out.println(format);
        LocalDateTime time =
                LocalDateTime.parse(format, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
        return time;
    }
}